home *** CD-ROM | disk | FTP | other *** search
Text File | 1990-10-25 | 6.3 KB | 219 lines | [TEXT/MPS ] |
- {[a-,body+,h-,o=100,r+,rec+,t=4,u+,#+,j=20/57/1$,n+]}
- { UBetterFeedbackCmd.inc1.p }
- { Copyright © 1988-1990 by Apple Computer, Inc. All rights reserved.}
-
- {--------------------------------------------------------------------------------------------------}
-
- TYPE
- QElemWithA5AndCounterPtr = ^QElemWithA5AndCounter;
- QElemWithA5AndCounter = RECORD
- OldA5: Longint; { A place to store the old value of A5 since
- when debugging the compiler trashes the
- value of A0 for any locals in the VBL task
- thus making the pointer to the
- paramblockrec unavailable }
- A5: Longint; { The value of A5 will be stored here to be
- available at VBL time }
- q: QElem; { our VBL queue element }
- END;
-
- {--------------------------------------------------------------------------------------------------}
-
- VAR
- gCounter: Longint; { our counter incremented in the VBL task }
- gOurVBLTask: QElemWithA5AndCounter; { our VBL task record }
- gSlot: INTEGER; { the slot our VBL is installed in }
-
- {--------------------------------------------------------------------------------------------------}
- {$Push} {$IFC qTrace} {$D+} {$ENDC}
- {$W+}
- {$R-}
- {$Init-}
- {$OV-}
- {$S ARes} { NOTE: must be resident! We *don't* want a segment load at interrupt time. }
-
- PROCEDURE IncOurVBLCounter;
- { our VBL task that increments the counter which is tested in WaitBetterFeedback }
-
- CONST
- theOffset = sizeof(Longint) * 2;
-
- BEGIN
- gOurVBLTask.OldA5 := SetA5(QElemWithA5AndCounterPtr(GetParmBlockPtr - theOffset)^.A5);
-
- WITH gOurVBLTask DO
- BEGIN
- q.vblQElem.vblCount := 1; { reprime the pump }
-
- gCounter := gCounter + 1; { increment our counter }
-
- IF SetA5(OldA5) = 0 THEN; { must discard the function result because
- when A5 gets reset we have no place to put
- the result }
- END;
- END;
- {$Pop}
-
- {--------------------------------------------------------------------------------------------------}
- {$S ADoCommand}
-
- PROCEDURE InstallOurVBL(aView: TView);
-
- { install a VBL task to increment a counter - used by TShapeCommand's TrackFeedback method }
-
- FUNCTION GetAVideoSlot:INTEGER;
-
- { return the video slot associated with the view's port }
-
- VAR
- aWindow: TWindow;
- aDefVideoRec: DefVideoRec;
- aGDHandle: GDHandle;
- aRect: Rect;
- aAuxDCEHandle: AuxDCEHandle;
-
- BEGIN
- aWindow := aView.GetWindow;
- IF (aWindow = NIL) THEN
- BEGIN
- GetVideoDefault(@aDefVideoRec);
- GetAVideoSlot := aDefVideoRec.sdSlot;
- END
- ELSE
- BEGIN
- aGDHandle := aWindow.GetMaxIntersectedDevice(aRect);
- aAuxDCEHandle := AuxDCEHandle(GetDCtlEntry(aGDHandle^^.gdRefNum));
- GetAVideoSlot := aAuxDCEHandle^^.dCtlSlot;
- END
- END;
-
- BEGIN
- gCounter := 0;
- WITH gOurVBLTask.q.vblQElem DO
- BEGIN
- qType := ORD(vType);
- vblAddr := @IncOurVBLCounter;
- vblCount := 1;
- vblPhase := 0;
- END;
- gOurVBLTask.A5 := Longint(GetA5);
- IF TrapExists(_SlotVInstall) THEN
- BEGIN
- gSlot := GetAVideoSlot;
- FailOSErr(SlotVInstall(@gOurVBLTask.q, gSlot));
- END
- ELSE
- FailOSErr(VInstall(@gOurVBLTask.q));
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$S ADoCommand}
-
- PROCEDURE RemoveOurVBL;
-
- { remove the VBL task we installed }
-
- BEGIN
- IF TrapExists(_SlotVRemove) THEN
- FailOSErr(SlotVRemove(@gOurVBLTask.q, gSlot))
- ELSE
- FailOSErr(VRemove(@gOurVBLTask.q));
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$S ASelCommand}
-
- PROCEDURE TBetterFeedbackCmd.IBetterFeedbackCmd(itsCmdNumber: CmdNumber; itsDocument: TDocument;
- itsView: TView; itsScroller: TScroller;
- betterFeedbackDesired: BOOLEAN);
-
- BEGIN
- ICommand(itsCmdNumber, itsDocument, itsView, itsScroller);
- fBetterFeedbackInstalled := NOT kInstall;
- fBetterFeedbackDesired := betterFeedbackDesired;
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$S ADoCommand}
-
- PROCEDURE TBetterFeedbackCmd.Free; OVERRIDE;
-
- BEGIN
- BetterFeedback(NOT kInstall);
- INHERITED Free;
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$S ADoCommand}
-
- FUNCTION TBetterFeedbackCmd.TrackMouse(aTrackPhase: TrackPhase; VAR anchorPoint, previousPoint,
- nextPoint: VPoint;
- mouseDidMove: Boolean): TCommand; OVERRIDE;
-
- BEGIN
- IF aTrackPhase = trackRelease THEN
- BetterFeedback(NOT kInstall);
- TrackMouse := SELF;
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$S ADoCommand}
-
- PROCEDURE TBetterFeedbackCmd.TrackFeedback(anchorPoint, nextPoint: VPoint; turnItOn,
- mouseDidMove: Boolean);
-
- BEGIN
- WaitBetterFeedback;
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$S ADoCommand}
-
- PROCEDURE TBetterFeedbackCmd.BetterFeedback(install: BOOLEAN);
-
- { use a VBL to improve TrackFeedback; eventually, this should go in TApplication.TrackMouse }
-
- BEGIN
- IF (fBetterFeedbackDesired = kBetterFeedbackDesired) THEN
- BEGIN
- IF (install = kInstall) & (fBetterFeedbackInstalled = NOT kInstall) THEN
- InstallOurVBL(fView)
- ELSE IF (install = NOT kInstall) & (fBetterFeedbackInstalled = kInstall) THEN
- RemoveOurVBL;
- fBetterFeedbackInstalled := install;
- END;
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$S MADoCommand}
-
- PROCEDURE TBetterFeedbackCmd.WaitBetterFeedback;
- { WaitBetterFeedback waits for our counter to change value }
-
- VAR
- t: Longint;
-
- BEGIN
- IF (fBetterFeedbackDesired = kBetterFeedbackDesired) THEN
- BEGIN
- IF (fBetterFeedbackInstalled = NOT kInstall) THEN
- BetterFeedback(kInstall);
- t := gCounter; { we'll wait til screen refresh }
- REPEAT UNTIL t <> gCounter; { let's hope this changes soon }
- END;
- END; {WaitBetterFeedback}
-
- {--------------------------------------------------------------------------------------------------}
- {$S AFields}
-
- PROCEDURE TBetterFeedbackCmd.Fields(PROCEDURE DoToField(fieldName: Str255; fieldAddr: Ptr;
- fieldType: INTEGER)); OVERRIDE;
-
- BEGIN
- DoToField('TBetterFeedbackCmd', NIL, bClass);
- DoToField('fBetterFeedbackInstalled', @fBetterFeedbackInstalled, bBoolean);
- DoToField('fBetterFeedbackDesired', @fBetterFeedbackDesired, bBoolean);
- INHERITED Fields(DoToField);
- END;
-
-